#include<stdio.h>
#include"process.h"
#include<unistd.h>
#include<stdlib.h>
#include<time.h>

double total=2048.0;//总的下载量为2048MB
double once = 0.1;//单次下载量
const int base = 10;

typedef void(*flush_t)(double total,double current);

void download(flush_t f)//模拟下载
{
	double current = 0.0;
	while(current<total)
	{
		int r = rand()%base+1;//随机数取值区间[1,10]
		double speed = r*once;//下载速度
		current+=speed;
		if(current>=total)
		{
			current=total;
		}
		usleep(10000);

		//根据真实的场景进行动态刷新
		f(total,current);

		//printf("test: %.1lf/%.1lf\r",current,total);
		//fflush(stdout);
	}
	printf("\n");
}
int main()
{
	srand(time(NULL));
	download(flushprocess);
	return 0;
}
